const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    theme: "",
    hide: false,
    o_openid: "",
    navHeight: app.globalData.navBarHeight,
    menuHeight: app.globalData.menuHeight,
    menuRight: app.globalData.menuRight,
    menuTop: app.globalData.menuTop,
  },

  changeTheme(e) {
    const { theme } = e.currentTarget.dataset;
    app.globalData.theme = theme;
    this.setData({ theme });
    if (theme == 1) {
      wx.setTabBarStyle({
        backgroundColor: "#a5646d",
      });
    } else if (theme == 2) {
      wx.setTabBarStyle({
        backgroundColor: "#1a1a1a",
      });
    } else if (theme == 3) {
      wx.setTabBarStyle({
        backgroundColor: "#86C6F6",
      });
    } else if (theme == 4) {
      wx.setTabBarStyle({
        backgroundColor: "#85a4cd",
      });
    }

    wx.setStorageSync("theme", theme);
  },

  goToBind() {
    wx.navigateTo({
      url: "/packageMine/pages/invitecode/invitecode",
    });
  },

  // 退出
  quit() {
    wx.showModal({
      title: "提示",
      content: "确定要退出嘛？",
      success: (result) => {
        if (result.confirm) {
          wx.removeStorageSync("openid");
          wx.reLaunch({
            url: "/pages/login/login",
          });
        }
      },
    });
  },

  // 打开半屏商城
  goShop() {
    wx.openEmbeddedMiniProgram({
      appId: "wx3a17e3521377c02e",
      success: (res) => { },
      fail: (res) => { },
      complete: (res) => { },
    });
  },

  goTopic() {
    wx.openEmbeddedMiniProgram({
      appId: "wxde6bdd2735dbcf04",
      success: (res) => { },
      fail: (res) => { },
      complete: (res) => { },
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const o_openid = wx.getStorageSync("o_openid");
    this.setData({
      theme: app.globalData.theme,
      hide: app.globalData.switch,
      o_openid,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});
